﻿using System;
using System.Collections.Generic;
using System.Text;
using ECC_EXT_Entity;
using NHibernate;
using NHibernate.Criterion;

namespace ECC_EXT_DAO.Dao
{
    public class DICOFFCategoryDao:DaoBase
    {
        public void SaveOrUpdate(DICOFFCategoryEntity _dicoffCategoryEntity)
        {
            using (ISession session = this.SessionFactory.OpenSession())
            {
                session.BeginTransaction();
                session.SaveOrUpdate(_dicoffCategoryEntity);
                session.Transaction.Commit();
            }
        }

        public IList<DICOFFCategoryEntity> GetByName(String strName)
        {
            using (ISession session = this.SessionFactory.OpenSession())
            {
                ICriteria criteria =
                    session.CreateCriteria<DICOFFCategoryEntity>();
                criteria.Add(Restrictions.Eq("Name", strName));
                //criteria.Add(Restrictions.Eq("CategoryFullName", _mailLogEntity.CategoryFullName));
                return
                criteria.List<DICOFFCategoryEntity>();
            }
        }


        public IList<DICOFFCategoryEntity> Search()
        {
            using (ISession session = this.SessionFactory.OpenSession())
            {
                ICriteria criteria =
                    session.CreateCriteria<DICOFFCategoryEntity>();
                //criteria.Add(Restrictions.Eq("MailNo", _mailLogEntity.MailNo));
                //criteria.Add(Restrictions.Eq("CategoryFullName", _mailLogEntity.CategoryFullName));
                return
                criteria.List<DICOFFCategoryEntity>();
            }
        }

        public int DeleteAll()
        {
            int res = 0;
            using (ISession session = this.SessionFactory.OpenSession())
            {
                session.BeginTransaction();
                res =
                session.CreateSQLQuery(@"delete from [T_ECC_EXT_DIC_OFFCategory]").ExecuteUpdate();
                session.Transaction.Commit();
            }
            return res;
        }
    }
}
